<?php
	$path_one = 'admin/admin_system';
	$path_two = 'admin/admin_module';
	$filename = 'admin/admin_admin_group';
	require_once("header.php");
	require_once("admin_comm.php");
	require_once $_site->get_handlepath('admin');

	$id = request('id') ;
	
	$group_info = admin_fun_find_group($id);//找出用的节点权限
	$mods = explode(',',$group_info['type_module']);
	$all_module = admin_fun_module_all();
	/*if($all_module){
		foreach ($all_module as $v){
			$group_array[$v['id']]=$v;
		}
	}*/
	$node = admin_fun_get_child_array($all_module);
?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>编辑用户组</title>
		<script type="text/javascript" charset="utf-8" src="/plugin/cooperation_base.js?v=1.0"></script>
		<script type="text/javascript" charset="utf-8">
			loader.file({
				skincss:['list']
			});
			$(function (){
				$('.c').each(function (){
					$(this).click(function (){
						if($(this).attr('checked')){
							$(this).parents('.cbox').find('.c-1,.c-2').attr('checked',true);
						}else{
							$(this).parents('.cbox').find('.c-1,.c-2').attr('checked',false);
						}
					})
				})
				$('.c-1').each(function (){
					$(this).click(function (){
						if($(this).attr('checked')){
							$(this).parent('h2').next('.c-1-1').find('.c-2').attr('checked',true);
						}else{
							$(this).parent('h2').next('.c-1-1').find('.c-2').attr('checked',false);
						}
					})
				})
				$('.c-2').each(function (){
					$(this).click(function (){
						if($(this).attr('checked')){
							$(this).parent('.c-1-1').prev().find('.c-1').attr('checked',true);
						}
					})
				})
				$('#all').click(function (){
					if($(this).attr('checked')){
						$('.add_group').find('input').attr('checked',true);
					}else{
						$('.add_group').find('input').attr('checked',false);
					}
				})
			})
		</script>
	</head>

	<body>
		<div class="main">
			<form action="/handle.php" method="post" id="group_form">
				<input type="hidden" name="h" value="admin/update_group">
				<input type="hidden" name="id" value="<?php echo $group_info['id']?>">
				<div class="power_box">
					<ul>
						<li>
							<p style="padding-top:5px;">权限组名称：</p>
							<input type="text" value="<?php echo $group_info['content']?>" name="content" id="name">
						</li>

						<li>
							<p>分配权限：<label name="errtip"></label></p>
							<input type="checkbox" class="noborder" id="all"><label for="all" id="message_select">全选</label><br />

							<div  class="add_group">
								<?php
									if($node){
										foreach($node as $v){
											if($v['leave']==1){
								?>
								<div class='cbox'>
												<h1>
													<input type="checkbox" class="noborder" id='c_<?php echo $v['id'] ;?>' value="<?php echo $v['id'] ;?>" <?php echo in_array($v['id'],$mods)?"checked":'' ;?> name="rs[]"><label for="c_<?php echo $v['id'] ;?>"><?php echo $v['content'] ;?></label>
												</h1>
												<?php
												if(!empty($v['child'])){
													echo "<span style='margin-left:15px;'>";
													foreach ($v['child'] as $v2){
														?>

													<h2>
														<input class="noborder" type="checkbox" <?php echo in_array($v2['id'],$mods)?"checked":'' ;?>  value="<?php echo $v2['id'] ;?>" name="rs[]" id="c2_<?php echo $v2['id'] ;?>">
														<label for="c2_<?php echo $v2['id'] ;?>"><?php echo $v2['content'] ;?></label>
													</h2>
														<?php
														if(!empty($v2['child'])){
															echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class='c-1-1'>";
															foreach ($v2['child'] as $v3){
																?>
																<input class="noborder" <?php echo in_array($v3['id'],$mods)?"checked":'' ;?> type="checkbox" value="<?php echo $v3['id'] ;?>" name="rs[]" id="c3_<?php echo $v3['id'] ;?>"> <label for="c3_<?php echo $v3['id'] ;?>"><?php echo $v3['content'] ;?></label>&nbsp;&nbsp;&nbsp;
																<?php
															}
															echo "</span>";
														}
													}
													echo "</span>";

												}
											}
											echo "</div>";
										}
									}

								?>

							</div>
						</li>
						<li><input type="submit" value="<?php echo !$id?'添加':'修改' ;?>" class="button1">  <a href="/admin/admin_admin_group">返回</a></li>
					</ul>
				</div>
			</form>
		</div>
	</body>
</html>
